/*
题目链接：https://leetcode.cn/problems/rotated-digits/description/
题目标题：788.旋转数字
提交时间：2024.10.7
*/

class Solution {
public:
    int rotatedDigits(int n) {
        set<char> g{'2','5','6','9'}, g1{'0','1','8'};
        int ans=0;
        for(int i=2;i<=n;i++){
            string s = to_string(i);
            bool gg1=1;
            bool gg=0;
            for(auto c:s){
                if(!g.count(c)&&!g1.count(c)){
                    gg1=0;
                    break;
                }
                if(g.count(c)){
                    gg=1;
                }
            }
            if(gg&gg1) ans++;
        }
        return ans;
    }
};